using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
	/// <summary>
	/// Summary description for ConnectData.
	/// </summary>
	public class ConnectData
	{
		public ConnectData()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		public static SqlConnection getConnection()
		{
            SqlConnection Connection = new SqlConnection(getConnectPoll());
            return Connection;
		}
        public static SqlConnection getConnection(string ip_str_database)
        {
            SqlConnection Connection = new SqlConnection(getConnectionByMaLink(ip_str_database));
            return Connection;
        }
        private static string getConnectionByMaLink(string ip_database)
        {
            string result = "server=" + System.Configuration.ConfigurationManager.AppSettings["datasource"].ToString() +
                ";database=" + ip_database +
                ";uid=" + System.Configuration.ConfigurationManager.AppSettings["userid"].ToString() +
                ";pwd=" + System.Configuration.ConfigurationManager.AppSettings["password"].ToString() +
                ";Connection Timeout=" + System.Configuration.ConfigurationManager.AppSettings["timeout"].ToString();
            //							ConfigurationSettings.AppSettings["timeout"].Length >0 ?";Connection Timeout=" + 
            //							ConfigurationSettings.AppSettings["timeout"]:"";
            return result;
        }
		private static string getConnectPoll()
		{
            string result = "server=" + System.Configuration.ConfigurationManager.AppSettings["datasource"].ToString() +
                ";database=" + System.Configuration.ConfigurationManager.AppSettings["Database"].ToString() +
                ";uid=" + System.Configuration.ConfigurationManager.AppSettings["userid"].ToString() +
                ";pwd=" + System.Configuration.ConfigurationManager.AppSettings["password"].ToString() + 
                ";Connection Timeout=" + System.Configuration.ConfigurationManager.AppSettings["timeout"].ToString();
//							ConfigurationSettings.AppSettings["timeout"].Length >0 ?";Connection Timeout=" + 
//							ConfigurationSettings.AppSettings["timeout"]:"";
			return result;
		}

	}
}
